From eb45b8083aa86d3a14e46d725d192fce0c946950 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 14 Feb 2023 07:19:18 +0100 Subject: [PATCH] png: Use GdkTexureDownloader when saving --- gdk/loaders/gdkpng.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/gdk/loaders/gdkpng.c b/gdk/loaders/gdkpng.c index 3d4172f9ed..fb4158f3cb 100644 --- a/gdk/loaders/gdkpng.c +++ b/gdk/loaders/gdkpng.c @@ -21,9 +21,9 @@ #include #include "gdkmemoryformatprivate.h" -#include "gdkmemorytextureprivate.h" +#include "gdkmemorytexture.h" #include "gdkprofilerprivate.h" -#include "gdktexture.h" +#include "gdktexturedownloaderprivate.h" #include "gdktextureprivate.h" #include "gsk/gl/fp16private.h" #include @@ -297,11 +297,12 @@ gdk_save_png (GdkTexture *texture) png_info *info; png_io io = { NULL, 0, 0 }; int width, height; - gsize stride; - const guchar *data; int y; - GdkMemoryTexture *memtex; GdkMemoryFormat format; + GdkTextureDownloader downloader; + GBytes *bytes; + gsize stride; + const guchar *data; int png_format; int depth; @@ -370,11 +371,15 @@ gdk_save_png (GdkTexture *texture) return NULL; } - memtex = gdk_memory_texture_from_texture (texture, format); + gdk_texture_downloader_init (&downloader, texture); + gdk_texture_downloader_set_format (&downloader, format); + bytes = gdk_texture_downloader_download_bytes (&downloader, &stride); + gdk_texture_downloader_finish (&downloader); + data = g_bytes_get_data (bytes, NULL); if (sigsetjmp (png_jmpbuf (png), 1)) { - g_object_unref (memtex); + g_bytes_unref (bytes); g_free (io.data); png_destroy_read_struct (&png, &info, NULL); return NULL; @@ -394,8 +399,6 @@ gdk_save_png (GdkTexture *texture) png_set_swap (png); #endif - data = gdk_memory_texture_get_data (memtex); - stride = gdk_memory_texture_get_stride (memtex); for (y = 0; y < height; y++) png_write_row (png, data + y * stride); @@ -403,7 +406,7 @@ gdk_save_png (GdkTexture *texture) png_destroy_write_struct (&png, &info); - g_object_unref (memtex); + g_bytes_unref (bytes); return g_bytes_new_take (io.data, io.size); } -- 2.30.2